<template>
  <div id="setingContent">
    <div class="seetingBody">
      <p class="seetingBody-title">系统设置</p>
      <div class="setting-box">
        <p class="setting-box-title btn-tab-setting">
          <em :class="tabActive==1?'activeTab':''" @click="tabBtn(1)">基本设置</em>
          <em :class="tabActive==2?'activeTab':''" @click="tabBtn(2)">校历设置</em>
        </p>
      </div>
      <basesetting v-if="tabActive==1"></basesetting>
      <schedule v-if="tabActive==2"></schedule>
    </div>
  </div>
</template>

<script>
import basesetting from './basesetting'
import schedule from './schedule'

export default {
  components: {
    basesetting,
    schedule
  },
  data () {
    return {
      tabActive: 1,
      infoForm: {
        name: '',
        url: '',
        baidu_appid: '',
        baidu_key: '',
        baidu_secret: '',
        map_id: ''
      },
      rules: {
        name: [
          {required: true, message: '填写学校名称', trigger: 'blur'}
        ],
        url: [
          {required: true, message: '填写学校网址', trigger: 'blur'}
        ],
        baidu_appid: [
          {required: true, message: '填写百度图片识别appid', trigger: 'blur'}
        ],
        baidu_key: [
          {required: true, message: '填写百度图片识别key', trigger: 'blur'}
        ],
        baidu_secret: [
          {required: true, message: '填写baidu_secret', trigger: 'blur'}
        ]
      },
      dialogIPVisible: false,
      dialogtype: 2,
    }
  },
  created () {
    console.log('23434')
    this.InitFn()
  },
  methods: {
    InitFn () {
      this.$fetch(this.api.system_setting, {}).then(res => {
        if (res.code === 0) {
          this.infoForm.name = res.vo.name
          this.infoForm.url = res.vo.url
          this.infoForm.baidu_appid = res.vo.baidu_appid
          this.infoForm.baidu_key = res.vo.baidu_key
          this.infoForm.baidu_secret = res.vo.baidu_secret
          this.infoForm.map_id = res.vo.map_id
        } else {
          this.$message({
            message: res.msg,
            type: 'error'
          })
        }
      })
    },
    tabBtn (option) {
      this.tabActive = option
    },
    onSubmit () {
      // 提交 this.$refs.infoForm.validate，这是表单验证
      this.$refs['infoForm'].validate((valid) => {
        if (valid) {
          this.$post(this.api.system_setting, this.infoForm).then(res => {
            if (res.code === 0) {
              this.$message({
                message: '设置成功',
                type: 'success'
              })
            } else {
              this.$message({
                message: res.msg,
                type: 'error'
              })
            }
          })
        }
      })
    },
    backloginUser () {
      this.$confirm('确认退出当前登入账号, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$router.push('/login')
      }).catch(() => {
      })
    },
    settingIPChange () {
      this.dialogIPVisible = true
    }
  }
}
</script>
